package com.yc.favorite.mapper;

import com.yc.favorite.bean.Tag;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface TagMapper {

    @Insert("insert into tag values (default,#{tname},1)")
    @Options(useGeneratedKeys = true, keyColumn = "tid", keyProperty = "tid")
    int insert(Tag tag);

    /**
     * 根据 tag 的名称 修改其分类的总数
     * @param tag
     * @return 返回: 数字表示更新的行数
     */
    @Update("update tag set tcount = tcount + 1 where tname=#{tname}")
    int updateCount(String tag);

    @Select("select * from tag")
    @Results(
            id = "rm1",
            value = {
                    @Result(column = "tid", property = "tid", id = true),
                    @Result(column = "tid", property = "fList",
                    // 这里不配 延迟加载, 因为返回是所以的分类和链接,
                    many = @Many(select =
                            "com.yc.favorite.mapper.FavoriteMapper.selectByTid"))
            }
    )
    List<Tag> selectAll();

    @Select("select * from tag where tname=#{tname}")
    Tag selectByTname(String tname);

}
